shadow:utility

Class HashMap<K,V>

Parent class

shadow:standard@Object

Interfaces

shadow:utility@Map<K,V>

class HashMap<K is CanHash and CanEqual<K>, V is CanEqual<V>>

Class HashMap<K,V> stores a map, also known as a symbol table, of key-value pairs with entries mapping keys of type K to values of type V. This map is implemented with a hash table that employs the chaining strategy for collision resolution, allowing keys to be added, found, and deleted in constant or near-constant time. HashMap<K,V> requires that type K has the CanHash interface but imposes no ordering requirement on keys. The TreeMap<K,V> class should be considered if key ordering is a requirement.

See Also

Create Summary

Modifiers Return Types Method and Description
public () create()

Creates an empty HashMap with a default capacity of 16 and maximum load factor of 0.75.

public () create(long initialCapacity)

Creates an empty HashMap with the specified capacity and maximum load factor.

public () create(long initialCapacity, float loadFactor)

Creates a HashMap with the specified initial capacity of buckets and the specified maximum load factor before all the key-value pairs are re-hashed.

Destroy Summary

Modifiers Return Types Method and Description
public () destroy()

Method Summary

Modifiers Return Types Method and Description
public (nullable V) add(K key, V value)

Stores value object in the location associated with the key and returns the old value if there was one at that location.

public (HashMap<K,V>) clear()

Removes all entries from the map and resets the capacity to default.

public readonly (boolean) containsKey(K key)

Checks to see if the map contains a key.

public readonly (boolean) containsValue(V value)

Checks to see if the map contains a particular value.

public readonly (HashMap<K,V>) copy(AddressMap addresses)
public readonly (nullable V) index(K key)

Retrieves the value associated with the key.

public () index(K key, V value)

Stores value object in the location associated with the key.

public readonly (boolean) isEmpty()

Checks whether or not the map is empty.

public readonly (Iterator<V>) iterator()

Creates an iterator to iterate over all the values in the map.

public (nullable V) remove(K key)

Removes the key-value pair associated with the key location.

protected () resize(long newCapacity)
public readonly (String) toString()

Produces a String representation of the map, listing all key-value pairs in an unspecified order.

Property Summary

Modifiers Return Types Method and Description
public readonly get (int) size()
public readonly get locked (long) sizeLong()

Gets the number of key-value pairs in the map.

Create Detail

create

public create() => ()

Creates an empty HashMap with a default capacity of 16 and maximum load factor of 0.75.

create

public create(long initialCapacity) => ()

Creates an empty HashMap with the specified capacity and maximum load factor.

Parameters

initialCapacity - initial capacity of the map

loadFactor - maximum load factor before the map is resized

create

public create(long initialCapacity, float loadFactor) => ()

Creates a HashMap with the specified initial capacity of buckets and the specified maximum load factor before all the key-value pairs are re-hashed. Note that the capacity will always be increased to the next power of 2 if it is not a power of 2.

Parameters

initialCapacity - initial number of buckets in the hash table

loadFactor - maximum load factor (buckets / keys) before all key-value pairs are re-hashed

Destroy Detail

destroy

public destroy() => ()

Method Detail

add

public add(K key, V value) => (nullable V)

Stores value object in the location associated with the key and returns the old value if there was one at that location. This operation runs in constant time in the best case and linear (but amortized constant) time if adding triggers a table resize.

Parameters

key - key location

value - value to store

Returns

old value at location or null if key was not already present

clear

public clear() => (HashMap<K,V>)

Removes all entries from the map and resets the capacity to default.

Returns

map after being cleared

containsKey

public readonly containsKey(K key) => (boolean)

Checks to see if the map contains a key. This operation runs in constant time or near-constant time.

Parameters

key - key to find

Returns

true if present

containsValue

public readonly containsValue(V value) => (boolean)

Checks to see if the map contains a particular value. This operation runs in time linear in the capacity of the hash table.

Parameters

value - value to find

Returns

true if present

copy

public readonly copy(AddressMap addresses) => (HashMap<K,V>)

index

public readonly index(K key) => (nullable V)

Retrieves the value associated with the key. If the key is not present, null is returned. This operation runs in constant or near-constant time.

Parameters

key - key to find

Returns

value at key location or null if not found

index

public index(K key, V value) => ()

Stores value object in the location associated with the key. This operation runs in constant time in the best case and linear (but amortized constant) time if adding triggers a table resize.

Parameters

key - key location

value - value to store

isEmpty

public readonly isEmpty() => (boolean)

Checks whether or not the map is empty.

Returns

true if the map is empty

iterator

public readonly iterator() => (Iterator<V>)

Creates an iterator to iterate over all the values in the map.

Returns

iterator

remove

public remove(K key) => (nullable V)

Removes the key-value pair associated with the key location. This operation runs in constant time or near-constant time.

Parameters

key - key to remove

Returns

value being removed or null if not present

resize

protected resize(long newCapacity) => ()

toString

public readonly toString() => (String)

Produces a String representation of the map, listing all key-value pairs in an unspecified order.

Returns

String representation

Property Detail

size

public readonly get size() => (int)

sizeLong

public readonly get locked sizeLong() => (long)

Gets the number of key-value pairs in the map.